const needUnit = ['fontSize', 'width', 'height', 'top', 'left', 'borderWidth', 'letterSpacing', 'borderRadius', 'lineHeight']

// 给指定元素添加px
export function formatStyle(style) {
  const result = {}
  Object.keys(style).forEach((key) => {
    result[key] = style[key]
    const value = result[key] + ''
    if (needUnit.includes(key) && !value.includes('px')) {
      result[key] += 'px'
    }
  })

  return result
}

// 去除指定元素的px
export function cutStyle(style) {
  const result = {}
  Object.keys(style).forEach((key) => {
    result[key] = style[key]
    const value = result[key] + ''
    if (needUnit.includes(key) && value.includes('px')) {
      result[key] = result[key].slice(0, -2)
    }
  })
  return result
}
